import pymysql
from movie_detai import *
# 打开数据库连接

conn = pymysql.connect(host="139.9.219.187",port=3306,user="lh",passwd="159753",db="movie_big_data",charset='utf8')
# 使用cursor()方法获取操作游标
cursor = conn.cursor()
#批量插入数据
try:
    #猫眼票房榜数据
    #sql_movie_rank_box_office = "insert into  movie_rank_box_office (name,release_date,total_box_office) values(%s,%s,%s)"
    #list_maoyan_rank_box_office = maoyan_rank_data()
    # cursor.executemany(sql_movie_rank_box_office, list_maoyan_rank_box_office)
    # conn.commit()

    #豆瓣评分排行
    #sql_movie_rank_score = "insert into  movie_rank_score (name,release_date,total_score) values(%s,%s,%s)"
    #list_douban_rank_score= douban_rank_data()
    # cursor.executemany(sql_movie_rank_score,list_douban_rank_score)
    # conn.commit()


    #豆瓣电影具体数据
    # sql_movie_detail = "insert into  movie_info (imdb,image_path,name,eng_name,release_date,director,scriptwriter,actor,type,production_area,language,remark_count,synopsis,lasts_time,score,star_five,star_four,star_three,star_two,star_one) " \
    #                    "values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
    # list_movie_detail = data_movie_detail("detail.txt")
    # print(len(list_movie_detail[462]))
    # print(list_movie_detail[462])
    # cursor.executemany(sql_movie_detail,list_movie_detail)
    # conn.commit()

    #电影评论信息
    # sql_movie_comment = "insert into  movie_comment (imdb,avatar,name,post_time,title,content) " \
    #                    "values(%s,%s,%s,%s,%s,%s)"
    # list_movie_comment = data_movie_comment("comment.txt")
    # print(list_movie_comment[2813])
    # cursor.executemany(sql_movie_comment,list_movie_comment)
    # conn.commit()

    #新榜票房数据
    # sql_new_movie = ""
    # list_new_movie = new_movie_data()
    # cursor.executemany(sql_new_movie,list_new_movie)
    # conn.commit()
    pass
except Exception as e:
    print(e)
    conn.rollback()
#关闭
finally:
    conn.close()
    cursor.close()
